<template>
  <div>

    <div>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <table   style="width: 100%">
    <tr>
      <td style="height: 100px;width: 350px;">
        <img src="https://img.58cdn.com.cn/ui8/house/detail/images/new58logo.png" style="height: 60px;">
      </td>
      <td style="padding-left: 100px;">
        <input @keyup.enter="handleQuery"  style="width: 600px;height: 60px;padding-left: 40px;border-width: 3px;border-color: #ff552e;border-style: solid;font-size: 18px;outline: none;"  v-model="queryParams.title"  placeholder="请输入房源相关信息">

  <button   @click="handleQuery" style="height: 60.5px; width: 80px;background: #ff552e;color: #fff;border-width: 0;font-size: 18px;padding-bottom: 3px;">
  搜房源</button>

      </td>
    </tr>
  </table>
</el-form>
    </div>
  <div>
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      style="width: 100%;"
    >
      <el-menu-item index="1" @click="showHouse()">租房</el-menu-item>
      <el-menu-item index="2">二手房</el-menu-item>
      <el-menu-item index="3">新房</el-menu-item>
      <el-menu-item index="4">商铺</el-menu-item>
      <el-menu-item index="5">写字楼</el-menu-item>
      <el-menu-item index="6">仓库</el-menu-item>
      <el-menu-item index="7">土地</el-menu-item>
      <el-menu-item index="8">车位</el-menu-item>
    </el-menu>
    <el-row :gutter="20">
      <el-col>
        <div class="button-wrapper" style="width: 100%">
          <el-button type="text" icon="el-icon-office-building" circle>
            <span>租房首页</span>
          </el-button>
          <el-button type="text" icon="el-icon-school" circle>
            <span>整租房</span>
          </el-button>
          <el-button type="text" icon="el-icon-house" circle>
            <span>合租房</span>
          </el-button>
          <el-button type="text" icon="el-icon-discount" circle>
            <span>个人住房</span>
          </el-button>
          <el-button type="text" icon="el-icon-price-tag" circle>
            <span>公寓出租</span>
          </el-button>
          <el-button type="text" icon="el-icon-office-building" circle>
            <span>租房小区</span>
          </el-button>
          <el-button type="text" icon="el-icon-finished" circle>
            <span>租金走势</span>
          </el-button>
          <el-button type="text" icon="el-icon-sort" circle>
            <span>租金排行</span>
          </el-button>
        </div>
      </el-col>

    </el-row>
    </div>
    <el-row>
      <el-col :span="5" v-for="houses in houseList" :key="houseList.id">
        <el-card class="house-card" style="height: 300px; width: 100%">
          <img :src="houses.houseImg" class="house-image" style="height: 120px; width: 300px;">
          <div class="house-info">
            <div class="house-title">
                <el-link
                  size="mini"
                  type="text"
                  @click="handleUpdate(houses)"
                  v-hasPermi="['system:house:edit']"
                >{{ houses.title }}</el-link>
<!--              <el-link type="primary" @click="showHouse(houses.id)">{{ houses.title }}-->
<!--              </el-link>-->
            </div>
            <div class="house-description">{{ houses.houseType }}</div>
            <div class="house-description">{{ houses.address }}</div>
            <div class="house-description">{{ houses.zufangType }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

    <!-- 添加或修改租房对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <div class="house-description">{{ form.title }}</div>
        <div class="house-description">
          <img :src="form.houseImg" class="house-image" style="height: 120px; width: 300px;">      </div>
          <div>租赁类型:{{ form.zufangType }}</div>
          <div>{{ form.price }} 元/月 押一付三 佣金：1月租金</div>
          <div>房屋类型:{{ form.houseType }}</div>
          <div>朝向楼层：:{{ form.orientationId }}</div>
          <div>所在小区：:{{ form.title }}</div>
          <div>所属区域：:{{ form.addr }}</div>
      </el-form>
    </el-dialog>
  </div>

</template>

<script>
import { listHouse, getHouse, delHouse, addHouse, updateHouse } from "@/api/system/house";

export default {
  name: "House",
  data() {
    return {
      activeIndex: '1',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 租房表格数据
      houseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleSelect(index) {
      this.activeIndex = index;
      // 根据索引加载不同的内容
    },
    /** 查询租房列表 */
    getList() {
      this.loading = true;
      listHouse(this.queryParams).then(response => {
        this.houseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        title: null,
        image: null,
        houseImg: null,
        houseType: null,
        concern: null,
        year: null,
        price: null,
        address: null,
        zufangType: null,
        orientationId: null,
        addr: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加租房";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getHouse(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "租房信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {5
          if (this.form.id != null) {
            updateHouse(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHouse(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除租房编号为"' + ids + '"的数据项？').then(function() {
        return delHouse(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/house/export', {
        ...this.queryParams
      }, `house_${new Date().getTime()}.xlsx`)
    }

  }
};
</script>


